//
//  CarOwnerOrdersDetailsViewController.m
//  UcarTest
//
//  Created by 陈曦 on 16/3/15.
//  Copyright © 2016年 chenxi. All rights reserved.
//

#import "CarOwnerOrdersDetailsViewController.h"
#import "Define.h"
#import "AFNetworking.h"
#import "NetRequestGroup.h"
#import "Access_token.h"
#import "MBProgressHUD.h"
#import "DIYCarDetailButton.h"
#import "RefuseViewController.h"
#import "CarOwnerOrdersViewController.h"
#import "CarDetailForgeViewController.h"
#import "CheckOutCarOwnerPhotoCollectionViewController.h"
#import "GiveBackCarOwnerPhotoCollectionViewController.h"

@interface CarOwnerOrdersDetailsViewController ()

@property (nonatomic, strong) UIScrollView *backgroundScrollView;

@property (nonatomic, strong) DIYCarDetailButton *carDetailBtn;

@end

@implementation CarOwnerOrdersDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //导航条设置
    [self navigationItemSet];
    
    //背景视图
    self.backgroundScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 48)];
    self.backgroundScrollView.backgroundColor = backgroundMainColor;
    [self.view addSubview:self.backgroundScrollView];
    self.backgroundScrollView.contentSize = CGSizeMake(kScreenWidth, kScreenHeight * 1.1);
    [self.view addSubview:self.backgroundScrollView];

    
    //网络请求
    [self NetworkRequests];
    

    
    
    
}

#pragma mark 网络请求
- (void) NetworkRequests{
    
    //初始化进度框，置于当前的View当中
    MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:HUD];
    HUD.label.text = @"正在加载";
    [HUD showAnimated:YES];//HUD开始
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    //申明返回的结果是json类型
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    //申明请求的数据是json类型
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    //如果报接受类型不一致请替换一致text/html或别的
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    Access_token *useAccess = [Access_token shareInstance];
    
    //传入的参数
    NSDictionary *para = @{
                           @"type" : @"1",
                           @"access_token" : useAccess.access_token,
                           @"id" : self.id,
                           @"order_type" : @"1"
                           };
    //你的接口地址
    NSString *url = [NSString stringWithFormat:@"%@%@", kRealmName,kNetCarOrderDetailView];
    //发送请求
    [manager POST:url parameters:para success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        [HUD hideAnimated:YES];
        
        
        NSDictionary *dic = responseObject;
        
//        NSString *status = dic[@"status"];
        
        //        NSString *msg = dic[@"msg"];
        
        NSDictionary *info = dic[@"info"];
        
        self.car_id = info[@"car_id"];
        
        //第一部分
        self.brand_str = info[@"car_brand"];
        
        self.model_str = info[@"car_model"];
        
        self.speed_box = info[@"car_speed_box"];
        
        self.place_str = info[@"car_place"];
        
        [self carDetailsView];
        
        //第二部分
        self.order_sn = info[@"order_sn"];
        
        self.anyDayStr = info[@"use_time"];
        
        //字符串转换成时间戳
        NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[info[@"open_time"] intValue]];
        NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
        [dateFormat setDateFormat:@"yyyy/MM/dd HH:mm"];
        NSString *open_time = [dateFormat stringFromDate:confromTimesp];
        
        NSDate *confromTimesp1 = [NSDate dateWithTimeIntervalSince1970:[info[@"end_time"] intValue]];
        NSDateFormatter *dateFormat1 = [[NSDateFormatter alloc]init];
        [dateFormat1 setDateFormat:@"yyyy/MM/dd HH:mm"];
        NSString *end_time = [dateFormat1 stringFromDate:confromTimesp1];

        self.openAndTimeStr = [NSString stringWithFormat:@"(%@ - %@)", open_time, end_time];
        
        self.addressStr = info[@"car_address"];
        
        self.order_status = info[@"order_status"];
        
        [self orderDetailsView];
        
        //第三部分
        self.chickOutPhotoStr = [NSString stringWithFormat:@"%@张", info[@"order_img_count_get"]];
        self.giveBackPhotoStr = [NSString stringWithFormat:@"%@张", info[@"order_img_count_restore"]];

        
        [self carPhotoView];
        
        //四
        self.car_earnings_money = info[@"car_earnings_money"];
        
        [self paymentAmountView];
        
        //五
        self.order_status = info[@"order_status"];
        
        if ([self.order_status isEqualToString:@"1"]) {
            
            [self buttonAdd];

        }
        
        
        
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
 
        [HUD hideAnimated:YES];

        //初始化提示框；
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"没有网络" preferredStyle:  UIAlertControllerStyleAlert];
        
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            //点击按钮的响应事件；
        }]];
        
        //弹出提示框；
        [self presentViewController:alert animated:true completion:nil];
        
        
    }];
    
}



//车辆信息
- (void) carDetailsView{
    
    //第一部分 车辆信息
    UIView *carDetails = [[UIView alloc] initWithFrame:CGRectMake(5, 15, kScreenWidth - 10, 70)];
    carDetails.layer.cornerRadius = 2;
    carDetails.layer.shadowOpacity = 1.0;
    carDetails.layer.shadowOffset = CGSizeMake(0.0, 0.0);
    carDetails.layer.shadowColor = [UIColor colorWithRed:215 / 255.0 green:215 / 255.0 blue:215 / 255.0 alpha:1].CGColor;
    carDetails.layer.shadowRadius = 1;
    carDetails.backgroundColor = [UIColor whiteColor];
    [self.backgroundScrollView addSubview:carDetails];
    
    //车辆信息跳转按钮
    self.carDetailBtn = [DIYCarDetailButton buttonWithType:UIButtonTypeCustom];
    self.carDetailBtn.frame = CGRectMake(0, 0, kScreenWidth - 10, 35);
    self.carDetailBtn.layer.cornerRadius = 2;
    self.carDetailBtn.layer.masksToBounds = YES;
    [self.carDetailBtn addTarget:self action:@selector(pushToCarDetailView) forControlEvents:UIControlEventTouchUpInside];
    [carDetails addSubview:self.carDetailBtn];
    
    //车品牌
    self.carNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 35, 25, 35)];
    self.carNameLabel.textAlignment = NSTextAlignmentCenter;
    self.carNameLabel.font = [UIFont systemFontOfSize:12];
    self.carNameLabel.textColor = [UIColor colorWithRed:85 / 255.0 green:85 / 255.0 blue:85 / 255.0 alpha:1];
    self.carNameLabel.text = self.brand_str;
    [carDetails addSubview:self.carNameLabel];
    
    //牌照
    self.licensePlateLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 35, 80, 35)];
    self.licensePlateLabel.textAlignment = NSTextAlignmentCenter;
    self.licensePlateLabel.font = [UIFont systemFontOfSize:12];
    self.licensePlateLabel.textColor = mainColor;
    self.licensePlateLabel.text = self.place_str;
    [carDetails addSubview:self.licensePlateLabel];
    
    //型号
    self.modelLabel = [[UILabel alloc] initWithFrame:CGRectMake(145, 45, 40, 15)];
    self.modelLabel.backgroundColor = [UIColor orangeColor];
    self.modelLabel.layer.cornerRadius = 2;
    self.modelLabel.layer.masksToBounds = YES;
    self.modelLabel.textAlignment = NSTextAlignmentCenter;
    self.modelLabel.font = [UIFont systemFontOfSize:12];
    self.modelLabel.textColor = [UIColor whiteColor];
    self.modelLabel.text = self.model_str;
    [carDetails addSubview:self.modelLabel];
    
    //自动或手动
    self.speed_boxLabel = [[UILabel alloc] initWithFrame:CGRectMake(205, 45, 40, 15)];
    self.speed_boxLabel.backgroundColor = [UIColor grayColor];
    self.speed_boxLabel.layer.cornerRadius = 2;
    self.speed_boxLabel.layer.masksToBounds = YES;
    self.speed_boxLabel.textAlignment = NSTextAlignmentCenter;
    self.speed_boxLabel.font = [UIFont systemFontOfSize:12];
    self.speed_boxLabel.textColor = [UIColor whiteColor];
    self.speed_boxLabel.text = self.speed_box;
    [carDetails addSubview:self.speed_boxLabel];
    
    
    //分割线
    UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 35, kScreenWidth - 20, 0.5)];
    lineLabel.backgroundColor = lineColor;
    [carDetails addSubview:lineLabel];
    
    
}

//订单信息
- (void) orderDetailsView{
    
    //第二部分 订单信息
    UIView *orderDetails = [[UIView alloc] initWithFrame:CGRectMake(5, 100, kScreenWidth - 10, 160)];
    orderDetails.layer.cornerRadius = 2;
    orderDetails.layer.shadowOpacity = 1.0;
    orderDetails.layer.shadowOffset = CGSizeMake(0.0, 0.0);
    orderDetails.layer.shadowColor = [UIColor colorWithRed:215 / 255.0 green:215 / 255.0 blue:215 / 255.0 alpha:1].CGColor;
    orderDetails.layer.shadowRadius = 1;
    orderDetails.backgroundColor = [UIColor whiteColor];
    [self.backgroundScrollView addSubview:orderDetails];
    
    UIImageView *orderImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 20, 20)];
    orderImageView.image = [UIImage imageNamed:@"icon-indent-blue"];
    [orderDetails addSubview:orderImageView];
    
    UILabel *orderInformation = [[UILabel alloc] initWithFrame:CGRectMake(40, 10, 80, 20)];
    orderInformation.text = @"订单信息";
    orderInformation.textAlignment = NSTextAlignmentLeft;
    orderInformation.textColor = [UIColor colorWithRed:51 / 255.0 green:51 / 255.0 blue:51 / 255.0 alpha:1];
    orderInformation.font = [UIFont systemFontOfSize:14];
    [orderDetails addSubview:orderInformation];
    
    UILabel *orderStatusLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth - 80, 10, 60, 20)];
    
    if ([self.order_status isEqualToString:@"0"] ) {
        orderStatusLabel.text = @"待支付";
    } else if ([self.order_status isEqualToString:@"1"]) {
        orderStatusLabel.text = @"待确认";
    } else if ([self.order_status isEqualToString:@"2"]) {
        orderStatusLabel.text = @"待支付";
    } else if ([self.order_status isEqualToString:@"3"]) {
        orderStatusLabel.text = @"用车";
    } else if ([self.order_status isEqualToString:@"4"]) {
        orderStatusLabel.text = @"已完成";
    } else if ([self.order_status isEqualToString:@"5"]) {
        orderStatusLabel.text = @"取消订单";
    }
    orderStatusLabel.textColor = mainColor;
    orderStatusLabel.textAlignment = NSTextAlignmentRight;
    orderStatusLabel.font = [UIFont systemFontOfSize:12];
    [orderDetails addSubview:orderStatusLabel];
    
    //用车时间标签
    UILabel *useCarTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, 70, 14)];
    useCarTimeLabel.text = @"订单号:";
    useCarTimeLabel.textAlignment = NSTextAlignmentRight;
    useCarTimeLabel.textColor = [UIColor colorWithRed:85 / 255.0 green:85 / 255.0 blue:85 / 255.0 alpha:1];
    useCarTimeLabel.font = [UIFont systemFontOfSize:12];
    [orderDetails addSubview:useCarTimeLabel];
    
    UILabel *orderNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 60, kScreenWidth / 5 * 3, 14)];
    orderNumberLabel.text = self.order_sn;
    orderNumberLabel.textAlignment = NSTextAlignmentLeft;
    orderNumberLabel.textColor = [UIColor colorWithRed:85 / 255.0 green:85 / 255.0 blue:85 / 255.0 alpha:1];
    orderNumberLabel.font = [UIFont systemFontOfSize:12];
    [orderDetails addSubview:orderNumberLabel];

    
    //用车时间
    UILabel *exchangeAdressLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 94, 70, 14)];
    exchangeAdressLabel.text = @"用车时间:";
    exchangeAdressLabel.textAlignment = NSTextAlignmentRight;
    exchangeAdressLabel.textColor = [UIColor colorWithRed:85 / 255.0 green:85 / 255.0 blue:85 / 255.0 alpha:1];
    exchangeAdressLabel.font = [UIFont systemFontOfSize:12];
    [orderDetails addSubview:exchangeAdressLabel];
    
    UILabel *useCarLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 94, 30, 14)];
    useCarLabel.text = self.anyDayStr;
    useCarLabel.textAlignment = NSTextAlignmentLeft;
    useCarLabel.textColor = [UIColor colorWithRed:85 / 255.0 green:85 / 255.0 blue:85 / 255.0 alpha:1];
    useCarLabel.font = [UIFont systemFontOfSize:12];
    [orderDetails addSubview:useCarLabel];
    
    UILabel *openEndTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(130, 84, kScreenWidth / 2 + 20, 36)];
    openEndTimeLabel.text = self.openAndTimeStr;
    openEndTimeLabel.textAlignment = NSTextAlignmentLeft;
    openEndTimeLabel.textColor = [UIColor colorWithRed:85 / 255.0 green:85 / 255.0 blue:85 / 255.0 alpha:1];
    openEndTimeLabel.font = [UIFont systemFontOfSize:10];
    [orderDetails addSubview:openEndTimeLabel];
    
    //交车地点
    UILabel *cashPledgeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 128, 70, 14)];
    cashPledgeLabel.text = @"交车地点:";
    cashPledgeLabel.textAlignment = NSTextAlignmentRight;
    cashPledgeLabel.textColor = [UIColor colorWithRed:85 / 255.0 green:85 / 255.0 blue:85 / 255.0 alpha:1];
    cashPledgeLabel.font = [UIFont systemFontOfSize:12];
    [orderDetails addSubview:cashPledgeLabel];
    
    //交车地点显示标签
    self.car_addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 118, kScreenWidth / 5 * 3, 36)];
    self.car_addressLabel.text = self.addressStr;
    self.car_addressLabel.numberOfLines = 0;
    self.car_addressLabel.lineBreakMode = NSLineBreakByWordWrapping;
    self.car_addressLabel.textAlignment = NSTextAlignmentLeft;
    self.car_addressLabel.textColor = [UIColor colorWithRed:85 / 255.0 green:85 / 255.0 blue:85 / 255.0 alpha:1];
    self.car_addressLabel.font = [UIFont systemFontOfSize:12];
    [orderDetails addSubview:self.car_addressLabel];

    
    //分割线
    UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 40, kScreenWidth - 20, 0.5)];
    lineLabel.backgroundColor = lineColor;
    [orderDetails addSubview:lineLabel];
    
}

//第三部分
//照片
- (void) carPhotoView{
    
    //第一部分 车辆信息
    UIView *carPhotos = [[UIView alloc] initWithFrame:CGRectMake(5, 280, kScreenWidth - 10, 85)];
    carPhotos.layer.cornerRadius = 2;
    carPhotos.layer.shadowOpacity = 1.0;
    carPhotos.layer.shadowOffset = CGSizeMake(0.0, 0.0);
    carPhotos.layer.shadowColor = [UIColor colorWithRed:215 / 255.0 green:215 / 255.0 blue:215 / 255.0 alpha:1].CGColor;
    carPhotos.layer.shadowRadius = 1;
    carPhotos.backgroundColor = [UIColor whiteColor];
    [self.backgroundScrollView addSubview:carPhotos];
    
    UIImageView *cameraPhotoIV = [[UIImageView alloc] initWithFrame:CGRectMake(10, 13, 20, 17)];
    cameraPhotoIV.image = [UIImage imageNamed:@"icon-photo"];
    [carPhotos addSubview:cameraPhotoIV];
    
    UILabel *takePhotosForCar = [[UILabel alloc] initWithFrame:CGRectMake(40, 15, 85, 15)];
    takePhotosForCar.text = @"拍摄车辆照片";
    takePhotosForCar.textAlignment = NSTextAlignmentCenter;
    takePhotosForCar.textColor = [UIColor colorWithRed:51 / 255.0 green:51 / 255.0 blue:51 / 255.0 alpha:1];
    takePhotosForCar.font = [UIFont systemFontOfSize:14];
    [carPhotos addSubview:takePhotosForCar];
    
    //提醒图片
    UIImageView *errorImageV = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth - 39, 13, 19, 19)];
    errorImageV.image = [UIImage imageNamed:@"icon-tixing"];
    [carPhotos addSubview:errorImageV];
    
    //灰色背景图
    UIImageView *grayBgIV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 45, kScreenWidth - 10, 40)];
    grayBgIV.image = [UIImage imageNamed:@"gary_bg"];
    [carPhotos addSubview:grayBgIV];
    
    UIView *spaceView = [[UIView alloc] initWithFrame:CGRectMake(kScreenWidth / 2 - 5, 55, 0.5, 20)];
    spaceView.backgroundColor = mainColor;
    [carPhotos addSubview:spaceView];
    
    UILabel *chickOutPhotolabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 45, kScreenWidth / 4 - 10, 40)];
    chickOutPhotolabel.backgroundColor = [UIColor clearColor];
    chickOutPhotolabel.text = @"取车照片:";
    chickOutPhotolabel.textAlignment = NSTextAlignmentRight;
    chickOutPhotolabel.textColor = [UIColor colorWithRed:85 / 255.0 green:85 / 255.0 blue:85 / 255.0 alpha:1];
    chickOutPhotolabel.font = [UIFont systemFontOfSize:12];
    [carPhotos addSubview:chickOutPhotolabel];
    
    UILabel *chickOutPhotolabelShow = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth / 4 - 5, 45, kScreenWidth / 4 - 10, 40)];
    chickOutPhotolabelShow.backgroundColor = [UIColor clearColor];
    chickOutPhotolabelShow.text = self.chickOutPhotoStr;
    chickOutPhotolabelShow.textAlignment = NSTextAlignmentCenter;
    chickOutPhotolabelShow.textColor = mainColor;
    chickOutPhotolabelShow.font = [UIFont systemFontOfSize:14];
    [carPhotos addSubview:chickOutPhotolabelShow];
    
    UILabel *giveBackPhotolabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth / 2, 45, kScreenWidth / 4 - 10, 40)];
    giveBackPhotolabel.backgroundColor = [UIColor clearColor];
    giveBackPhotolabel.text = @"还车照片:";
    giveBackPhotolabel.textAlignment = NSTextAlignmentRight;
    giveBackPhotolabel.textColor = [UIColor colorWithRed:85 / 255.0 green:85 / 255.0 blue:85 / 255.0 alpha:1];
    giveBackPhotolabel.font = [UIFont systemFontOfSize:12];
    [carPhotos addSubview:giveBackPhotolabel];
    
    UILabel *giveBackPhotolabelShow = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth / 4 * 3, 45, kScreenWidth / 4 - 20, 40)];
    giveBackPhotolabelShow.backgroundColor = [UIColor clearColor];
    giveBackPhotolabelShow.text = self.giveBackPhotoStr;
    giveBackPhotolabelShow.textAlignment = NSTextAlignmentCenter;
    giveBackPhotolabelShow.textColor = mainColor;
    giveBackPhotolabelShow.font = [UIFont systemFontOfSize:12];
    [carPhotos addSubview:giveBackPhotolabelShow];
    
    UIButton *checkOutPhotoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    checkOutPhotoBtn.frame = CGRectMake(0, 45, kScreenWidth / 2 - 20, 40);
    [checkOutPhotoBtn addTarget:self action:@selector(checkOutPhotoBtnPush) forControlEvents:UIControlEventTouchUpInside];
    [carPhotos addSubview:checkOutPhotoBtn];
    
    UIButton *giveBackPhotoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    giveBackPhotoBtn.frame = CGRectMake(kScreenWidth / 2 - 10, 45, kScreenWidth / 2 - 20, 40);
    [giveBackPhotoBtn addTarget:self action:@selector(giveBackPhotoBtnPush) forControlEvents:UIControlEventTouchUpInside];
    [carPhotos addSubview:giveBackPhotoBtn];


}

#pragma mark 取车照片
- (void)checkOutPhotoBtnPush{
    
    CheckOutCarOwnerPhotoCollectionViewController *checkOut = [[CheckOutCarOwnerPhotoCollectionViewController alloc] init];
    
    checkOut.order_id = self.id;
    
    [self.navigationController pushViewController:checkOut animated:nil];
    
}

#pragma mark 还车照片
- (void) giveBackPhotoBtnPush {
    
    GiveBackCarOwnerPhotoCollectionViewController *giveBack = [[GiveBackCarOwnerPhotoCollectionViewController alloc] init];
    
    giveBack.order_id = self.id;
    
    [self.navigationController pushViewController:giveBack animated:nil];
    
}


#pragma mark 第四部分支付金额视图
- (void) paymentAmountView {
    
    //第一部分 支付金额
    UIView *paymentAmountBGView = [[UIView alloc] initWithFrame:CGRectMake(5, 385, kScreenWidth - 10, 40)];
    paymentAmountBGView.layer.cornerRadius = 2;
    paymentAmountBGView.layer.shadowOpacity = 1.0;
    paymentAmountBGView.layer.shadowOffset = CGSizeMake(0.0, 0.0);
    paymentAmountBGView.layer.shadowColor = [UIColor colorWithRed:215 / 255.0 green:215 / 255.0 blue:215 / 255.0 alpha:1].CGColor;
    paymentAmountBGView.layer.shadowRadius = 1;
    paymentAmountBGView.backgroundColor = [UIColor whiteColor];
    [self.backgroundScrollView addSubview:paymentAmountBGView];
    
    UIImageView *payImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 19, 20)];
    payImageView.image = [UIImage imageNamed:@"icon-cost"];
    [paymentAmountBGView addSubview:payImageView];
    
    UILabel *earningsLabel = [[UILabel alloc] initWithFrame:CGRectMake(39, 15, 30, 15)];
    earningsLabel.text = @"收益";
    earningsLabel.textAlignment = NSTextAlignmentLeft;
    earningsLabel.textColor = [UIColor colorWithRed:51 / 255.0 green:51 / 255.0 blue:51 / 255.0 alpha:1];
    earningsLabel.font = [UIFont systemFontOfSize:15];
    [paymentAmountBGView addSubview:earningsLabel];
    
    
    UILabel *unitsLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth - 32, 16, 12, 12)];
    unitsLabel.text = @"元";
    unitsLabel.textAlignment = NSTextAlignmentCenter;
    unitsLabel.textColor = [UIColor colorWithRed:85 / 255.0 green:85 / 255.0 blue:85 / 255.0 alpha:1];
    unitsLabel.font = [UIFont systemFontOfSize:12];
    [paymentAmountBGView addSubview:unitsLabel];
    
    UILabel *earningsShowLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth - 100, 16, 65, 12)];
    earningsShowLabel.textColor = mainColor;
    earningsShowLabel.textAlignment = NSTextAlignmentRight;
    earningsShowLabel.text = self.car_earnings_money;
    earningsShowLabel.font = [UIFont systemFontOfSize:12];
    [paymentAmountBGView addSubview:earningsShowLabel];
    
    
}
#pragma mark 导航条设置
- (void) navigationItemSet {
    self.navigationController.navigationBarHidden = NO;
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.font = [UIFont boldSystemFontOfSize:18];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"车主订单详情";
    self.navigationItem.titleView = titleLabel;
    self.navigationController.navigationBar.barTintColor = mainColor;
    self.view.backgroundColor = backgroundMainColor;
    
    
    //重定义返回键
    UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
    back.frame = CGRectMake(0, 0, 22, 22);
    [back setImage:[UIImage imageNamed:@"iconfont-fanhui-white"] forState:UIControlStateNormal];
    [back addTarget:self action:@selector(backTpMainView) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backBar = [[UIBarButtonItem alloc] initWithCustomView:back];
    self.navigationItem.leftBarButtonItem = backBar;
    
    //重定义客服电话按钮
    UIButton *phone = [UIButton buttonWithType:UIButtonTypeCustom];
    phone.frame = CGRectMake(0, 0, 22, 22);
    [phone setImage:[UIImage imageNamed:@"icon-phone"] forState:UIControlStateNormal];
    [phone addTarget:self action:@selector(CustomerServiceCall) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *phoneBar = [[UIBarButtonItem alloc] initWithCustomView:phone];
    self.navigationItem.rightBarButtonItem = phoneBar;
    
    
}

#pragma mark 客服电话
- (void) CustomerServiceCall {
    
    NSString *title = NSLocalizedString(@"提示", nil);
    NSString *message = NSLocalizedString(@"确认拨打客服电话", nil);
    NSString *cancelButtonTitle = NSLocalizedString(@"取消", nil);
    NSString *otherButtonTitle = NSLocalizedString(@"确认", nil);
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    
    // Create the actions.
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        
        
    }];
    
    UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://4009922955"]];
        
    }];
    
    [alertController addAction:cancelAction];
    [alertController addAction:otherAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
    
    
}

//返回列表
- (void)backTpMainView{
    
    
    CarOwnerOrdersViewController *carowner = [[CarOwnerOrdersViewController alloc] init];
    
    [self.navigationController pushViewController:carowner animated:nil];
    
    
}

- (void) buttonAdd {
    
    //拒绝下单按钮
    UIButton *confirmationOrderBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    confirmationOrderBtn.frame = CGRectMake(20, kScreenHeight - 41, (kScreenWidth - 40) / 2 - 10, 34);
    confirmationOrderBtn.layer.cornerRadius = 3;
    confirmationOrderBtn.layer.masksToBounds = YES;
    confirmationOrderBtn.backgroundColor = [UIColor whiteColor];
    confirmationOrderBtn.layer.borderWidth = 1;
    confirmationOrderBtn.layer.borderColor = [UIColor colorWithRed:0 / 255.0 green:137 / 255.0 blue:225 / 255.0 alpha:1].CGColor;
    [confirmationOrderBtn setTitle:@"拒绝" forState:UIControlStateNormal];
    [confirmationOrderBtn setTitleColor:[UIColor colorWithRed:0 / 255.0 green:137 / 255.0 blue:225 / 255.0 alpha:1] forState:UIControlStateNormal];
    [confirmationOrderBtn addTarget:self action:@selector(confirmationOrderPush) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:confirmationOrderBtn];

    //确认下单按钮
    UIButton *defineOrderBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    defineOrderBtn.frame = CGRectMake(kScreenWidth / 2 + 10 , kScreenHeight - 41, (kScreenWidth - 40) / 2 - 10, 34);
    defineOrderBtn.layer.cornerRadius = 3;
    defineOrderBtn.layer.masksToBounds = YES;
    defineOrderBtn.backgroundColor = mainColor;
    [defineOrderBtn setTitle:@"确认" forState:UIControlStateNormal];
    defineOrderBtn.titleLabel.tintColor = [UIColor whiteColor];
    [defineOrderBtn addTarget:self action:@selector(defineOrderPush) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:defineOrderBtn];

}

#pragma mark 拒绝跳转
- (void) confirmationOrderPush {
    
    RefuseViewController *refuseVC = [[RefuseViewController alloc] init];
    
    refuseVC.id = self.id;
    
    [self.navigationController pushViewController:refuseVC animated:nil];
    
}

#pragma mark 确认跳转
- (void) defineOrderPush {
    
    [self NetworkRequests:self.id];
    
}

#pragma mark 网络请求
- (void) NetworkRequests:(NSString *)orderID{
    
    //初始化进度框，置于当前的View当中
    MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:HUD];
    HUD.label.text = @"正在加载";
    [HUD showAnimated:YES];//HUD开始
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    //申明返回的结果是json类型
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    //申明请求的数据是json类型
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    //如果报接受类型不一致请替换一致text/html或别的
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    Access_token *useAccess = [Access_token shareInstance];
    
    //传入的参数
    NSDictionary *para = @{
                           @"type" : @"1",
                           @"access_token" : useAccess.access_token,
                           @"audit_type" : @"0",
                           @"id" : orderID
                           };
    //你的接口地址
    NSString *url = [NSString stringWithFormat:@"%@%@", kRealmName, kNetOrderAudit];
    //发送请求
    [manager POST:url parameters:para success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        [HUD hideAnimated:YES];
        
        
        NSDictionary *dic = responseObject;
        
        self.status = dic[@"status"];
        
        self.msg = dic[@"msg"];
        
        
        [self resultAnalysis];
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        [HUD hideAnimated:YES];
        
        //初始化提示框；
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"没有网络" preferredStyle:  UIAlertControllerStyleAlert];
        
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            //点击按钮的响应事件；
        }]];
        
        //弹出提示框；
        [self presentViewController:alert animated:true completion:nil];
        
    }];
    
}


#pragma mark 返回值分析
- (void) resultAnalysis {
    
    int status = [self.status intValue];
    
    switch (status) {
        case 99:{
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //点击按钮的响应事件；
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
        }
            
            break;
        case 98:{
            
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //点击按钮的响应事件；
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
        }
            break;
        case 97:
        {
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //点击按钮的响应事件；
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
        }
            
            break;
        case 96:
        {
            
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //点击按钮的响应事件；
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
        }
            
            break;
        case 1:
        {
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //点击按钮的响应事件；
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
        }
            break;
        case 2:
        {
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:self.msg preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //点击按钮的响应事件；
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
        }
            break;
            
        case 100:
        {
            
            //初始化提示框；
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"确认成功" preferredStyle:  UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //点击按钮的响应事件；
                
                CarOwnerOrdersViewController *carowner = [[CarOwnerOrdersViewController alloc] init];
                
                [self.navigationController pushViewController:carowner animated:nil];
                
            }]];
            
            //弹出提示框；
            [self presentViewController:alert animated:true completion:nil];
            
        }
            break;
            
        default:
            break;
    }
    
    
    
}

//车辆详情
- (void) pushToCarDetailView {
    
    CarDetailForgeViewController *carDetailVC = [[CarDetailForgeViewController alloc] init];
    carDetailVC.carIDStr = self.car_id;
    
    [self.navigationController pushViewController:carDetailVC animated:nil];
    
}


@end
